package cn.edu.sgu.www.mhxysy.service.system.impl;

import cn.edu.sgu.www.mhxysy.consts.CustomPackages;
import cn.edu.sgu.www.mhxysy.dto.system.PermissionInitDTO;
import cn.edu.sgu.www.mhxysy.entity.system.Permission;
import cn.edu.sgu.www.mhxysy.feign.clients.pms.PmsFeignService;
import cn.edu.sgu.www.mhxysy.service.system.PermissionService;
import cn.edu.sgu.www.mhxysy.util.ResourceScanner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    /**
     * 服务名
     */
    @Value("${spring.application.name}")
    private String service;

    private final PmsFeignService feignService;
    private final ResourceScanner resourceScanner;

    @Autowired
    public PermissionServiceImpl(
            PmsFeignService feignService,
            ResourceScanner resourceScanner) {
        this.feignService = feignService;
        this.resourceScanner = resourceScanner;
    }

    @Override
    public void resources() throws ClassNotFoundException {
        // 获取扫描结果
        List<Permission> permissions = resourceScanner.scan(CustomPackages.controllerPackage);

        PermissionInitDTO permissionInitDTO = new PermissionInitDTO();

        permissionInitDTO.setService(service);
        permissionInitDTO.setPermissions(permissions);

        feignService.resources(permissionInitDTO);
    }

}